/**
 * @param {number[]} nums
 * @return {number}
 * 输入：nums = [1,1,1,2,2,3]
输出：5, nums = [1,1,2,2,3]
 */
var removeDuplicates = function (nums) {
  let index = 0
  let last = null
  let i = 0
  while (i < nums.length) {
    if (nums[i] === last) {
      index++
      if (index >= 2) {
        nums.splice(i, 1)
        i--
      }
    } else {
      index = 0
    }
    last = nums[i]
    i++
  }
  return nums.length
}
console.log(removeDuplicates([1, 1, 1, 2, 2, 3]))
